import com.arangodb.tinkerpop.gremlin.utils.ArangoDBConfigurationBuilder;
import org.apache.commons.configuration.BaseConfiguration;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;

/**
 * Created By acproject@qq.com on 3/3/22 1:31 PM
 */
public class test1 {
    public test1() throws Exception {
        ArangoDBConfigurationBuilder builder = new ArangoDBConfigurationBuilder();
        builder.graph("modern")
                .withVertexCollection("software")
                .withEdgeCollection("hardware")
                .withVertexCollection("person")
                .withEdgeCollection("knows")
                .withEdgeCollection("created")
                .configureEdge("knows", "person", "person")
                .configureEdge("created", "person", "software")
                .arangoHosts("172.17.0.4:8529")
                .arangoPassword("root")
                .arangoTimeout(3000)
                .arangoUser("root")
                .dataBase("test2");

        BaseConfiguration conf = builder.build();
        Graph graph = GraphFactory.open(String.valueOf(conf));
        GraphTraversalSource gts = new GraphTraversalSource(graph);

        GraphTraversalSource g = gts.clone();
        var person = Person.builder().age(29).name("marko").label("person").build();
        var software = Software.builder().label("software").lang("java").name("lop").build();
        var edgeProp = EdgeProperties.builder().label("created").Weight(0.4f).build();
        Vertex v1 = null;
        if (g.V().has(person.getLabel()).hasNext()){
            // do not
        }else {
            v1 = g.addV(person.getLabel()).property(T.label , person.getLabel()).property("age:", person.getAge()).next();        }
        Vertex v2 = null;
        if (g.V().has(software.getLabel()).hasNext()) {
            // do not
        }
//        Vertex v2 =  g.addV(software.getLabel()).property(T.label, software.getLabel(), "lang:" + software.getLang(),"name:"+ software.getName()).next();
        else {
             v2 = g.getGraph().addVertex(T.label, software.getLabel(),
              "lang", software.getLang(),
                     "name", software.getName());
        }

//        g.addE(edgeProp.getLabel()).property(T.label ,edgeProp.getLabel(), T.key, "weight", T.value, edgeProp.getWeight());
//        g.addE("knows").from(v1).to(v1);
        g.addE("create").from(v1).to(v2);

        g.close();
        graph.close();

    }

    public static void main(String[] args) throws Exception {
        test1 oo = new test1();
    }
}
